<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>好友列表</title>
    <jsp:include page="include/commonfiles.jsp"/>
    <style>
        thead{
            background-color: wheat;
            width: 80%;
        }
    </style>
</head>
<body>
<jsp:include page="include/silderbar.jsp"/>
<div class="layui-body">
    <div class="container">
        <div class="row r">
            <div class="col-md-10">
                <table class="table table-hover" border="2">
                    <caption style=""><h3><b>好友列表</b></h3></caption>
                    <thead>
                    <th>姓名</th>
                    <th>昵称</th>
                    <th>性别</th>
                    <th>电话</th>
                    <th>地址</th>
                    <th>编辑</th>
                    </thead>
                    <tbody>
                    <c:forEach items="${pageInfo.list}" var="firend">
                        <tr>
                            <td>${firend.username}</td>
                            <td>${firend.nickname}</td>
                            <td>${firend.sex}</td>
                            <td>${firend.phone}</td>
                            <td>${firend.locals}</td>
                            <td>
                                <button id="delete" class="btn btn-warning btn-sm" onclick="delet('${firend.username}')">
                                    <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
                                    删除
                                </button>
                                <button class="btn btn-success btn-sm">
                                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                                    聊天
                                </button>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                当前${pageInfo.pageNum }页，总共${pageInfo.pages }页，总共${pageInfo.total }条记录
            </div>
            <div class="col-md-6">
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        <li><a href="${path}/emps?pn=1">首页</a></li>
                        <c:if test="${pageInfo.hasPreviousPage }">
                            <li>
                                <a href="${path}/emps?pn=${pageInfo.pageNum-1}" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                        </c:if>
                        <c:forEach items="${pageInfo.navigatepageNums }" var="page">
                            <c:if test="${page==pageInfo.pageNum }">
                                <li class="active"><a href="${path }/emps?pn=${page}">${page}</a></li>
                            </c:if>
                            <c:if test="${page!=pageInfo.pageNum }">
                                <li><a href="${path}/emps?pn=${page}">${page}</a></li>
                            </c:if>
                        </c:forEach>
                        <c:if test="${pageInfo.hasNextPage }">
                            <li>
                                <a href="${path}/emps?pn=${pageInfo.pageNum+1 }" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        </c:if>
                        <li><a href="${path}/emps?pn=${pageInfo.pages}">末页</a></li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</div>
<script src="${path}/js/jquery-3.6.0.js"></script>
<script>
    <%--根据好友username删除好友--%>
    function delet(right_name){
        var flag = confirm("你确定要删除吗？");
        if (flag==true){
            $.ajax({
                url:"${pageContext.request.contextPath}/deletefirend",
                type:"post",
                async:false,
                data:{"left_name":"${userInfo.username}","right_name":right_name},
                // dataType: 'json',
                success:function(data){
                    if(data.stateCode.trim()=="1") {
                        window.location.reload();
                    }
                }
            })

        }
    }
</script>
</body>
</html>